package cn.iocoder.yudao.module.crossborder.product.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.product.api.dto.ProductDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.ProductCreateReqDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.CategoryDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.BrandDTO;
import cn.iocoder.yudao.module.crossborder.product.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 商品管理 API 接口
 *
 * @author LHL
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 商品管理")
public interface ProductApi {

    String PREFIX = ApiConstants.PREFIX + "/product";

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "获得商品")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<ProductDTO> getProduct(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "获得商品列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<ProductDTO>> getProductList(@RequestParam("ids") @NotNull List<Long> ids);

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建商品")
    CommonResult<Long> createProduct(@RequestBody @Valid ProductCreateReqDTO createReq);

    @GetMapping(PREFIX + "/category/get")
    @Operation(summary = "获得商品分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<CategoryDTO> getCategory(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/category/list")
    @Operation(summary = "获得商品分类列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<CategoryDTO>> getCategoryList(@RequestParam("ids") @NotNull List<Long> ids);

    @GetMapping(PREFIX + "/brand/get")
    @Operation(summary = "获得商品品牌")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<BrandDTO> getBrand(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/brand/list")
    @Operation(summary = "获得商品品牌列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<BrandDTO>> getBrandList(@RequestParam("ids") @NotNull List<Long> ids);

    @PostMapping(PREFIX + "/update-stock")
    @Operation(summary = "更新商品库存")
    @Parameter(name = "productId", description = "商品编号", required = true, example = "1024")
    @Parameter(name = "quantity", description = "库存数量", required = true, example = "100")
    CommonResult<Boolean> updateStock(@RequestParam("productId") @NotNull Long productId,
                                     @RequestParam("quantity") @NotNull Integer quantity);

    @PostMapping(PREFIX + "/update-price")
    @Operation(summary = "更新商品价格")
    @Parameter(name = "productId", description = "商品编号", required = true, example = "1024")
    @Parameter(name = "price", description = "商品价格", required = true, example = "99.99")
    @Parameter(name = "currency", description = "货币代码", required = true, example = "USD")
    CommonResult<Boolean> updatePrice(@RequestParam("productId") @NotNull Long productId,
                                     @RequestParam("price") @NotNull String price,
                                     @RequestParam("currency") @NotNull String currency);

}
